home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
001
/
commdev.arc
/
TTY.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-11-21
|
4KB
|
157 lines
page 60,132
;***********************************************************
;** TTY Program to Test the RS232 Device Driver **
;** Author: Greg Haley **
;***********************************************************
name tty
title Interrupt Driven TTY Program
cr equ 13
lf equ 10
console_io equ 6
aux_in equ 3fh
aux_out equ 4
print_string equ 9
aux_handle equ 3
write_control equ 4403h
read_control equ 4402h
terminate equ 4c00h
msdos equ 21h
code segment
assume cs:code, ds:code, ss:code
org 100h
tty proc near
start:
jmp go
;***********************************************************
;** Variables **
;***********************************************************
db 40 dup (?) ; Stack
t_stack db 0
connect db 0 ; Connect flag
r_len dw 0 ; Receive buffer length
DCB db 01000101b ; LEN, raise DTR
DCW dw 1100000001000000b ; Port 1, 1200, 8N1
off db 0 ; Drop DTR & reset driver
buffer db ? ; Storage for char read
init_msg:
db 'TTY emulation begun.'
db cr,lf,'Press any function key to exit.',cr,lf,lf,'$'
dcb_error:
db cr,lf,'Error writing DCB.$'
off_error:
db cr,lf,'Error disconnecting.$'
dcw_error:
db cr,lf,'Error writing DCW.$'
len_error:
db cr,lf,'Error reading receive buffer length.$'
;***********************************************************
;** Program starts here **
;***********************************************************
go:
mov sp,offset t_stack
; print signon msg
mov dx,offset init_msg
mov ah,print_string
int msdos
;***********************************************************
;** Initialize the driver **
;***********************************************************
; Send DCB to driver, AUX is already open
mov bx,aux_handle
mov dx,offset DCB
mov cx,1
mov ax,write_control
int msdos
jnc DCB_ok
mov dx,offset dcb_error ; If error print msg & exit
mov ah,print_string
int msdos
jmp exit
DCB_ok:
; Send DCW to driver
mov dx,offset DCW
mov cx,2
mov ax,write_control
int msdos
jnc DCW_ok
mov dx,offset dcw_error ; If error print msg & exit
mov ah,print_string
int msdos
jmp exit
DCW_ok:
mov byte ptr connect,1 ; Set connect flag
;***********************************************************
;** Main Comm Routine **
;***********************************************************
wait4chr:
cmp byte ptr connect,0 ; Are we on-line?
jz exit ; No, exit
; Read 1 char from AUX
mov bx,aux_handle
mov dx,offset buffer
mov cx,1
mov ah,aux_in ; Yes, read & display char
int msdos
; Check for keyboard input
mov dl,0ffh ; Is a char ready at keyboard?
mov ah,console_io
int msdos
jc wait4chr ; No, loop again (DOS 2.xx)
jz wait4chr ; No, loop again (DOS 3.xx)
; (Why did Microsoft change???)
or al,al ; Yes, was it a null of F-key?
jnz send_char ; No, send char
mov byte ptr connect,0 ; Yes, disconnect
mov dl,0ffh ; Read 2nd half of F-Key
mov ah,console_io
int msdos
jmp short exit ; and exit
; Send a char to AUX
send_char:
mov dl,al ; No, send char
mov ah,aux_out
int msdos
jmp short wait4chr
;***********************************************************
;** Disconnect and reset the driver **
;***********************************************************
exit:
mov bx,aux_handle
mov dx,offset off
mov cx,1
mov ax,write_control
int msdos
jnc off_ok
mov dx,offset off_error ; If error print msg & exit
mov ah,print_string
int msdos
off_ok:
mov ax,terminate ; Terminate program
int msdos
tty endp
code ends
end start